<?php
namespace App\Http\Controllers\System;

use App\Http\Controllers\Controller;
use App\Models\Frag;
use App\Models\MBonusLog;
use App\Models\MClassify;
use App\Models\MConsumeLog;
use App\Models\MFeedback;
use App\Models\MNews;
use App\Models\MNotices;
use App\Models\MSwitchCoinLog;
use App\Models\MTransferLog;
use App\Models\MUser;
use App\Models\MWallet;
use App\Models\MWithdrawLog;
use App\Templates\CommonHandle;
use App\Utils\GDUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

/**
 * 会员控制器
 */
class UserController extends Controller
{
    use CommonHandle;

    /**
     * 前台显示页面
     */
    public function loginPage()
    {

        if(cache("kv_site_open") == 2) { //网站开启

            //公司发展
            $this->data['develops'] = Frag::where('slug','like','us-content-develop%')->get();

            //个人信息
            $this->data['persons'] = Frag::where('slug','like','us-company-people%')->get();
            //业务
            $this->data['operations'] = Frag::where('slug','like','operation-content%')->get();
            //新闻
            $this->data['news'] = Frag::where('slug','like','news-content%')->get();
            return view('system.index')->with($this->data);
        }
        if(cache("kv_site_open") == 1){
            //个人信息
            $this->data['persons'] = Frag::where('slug','like','friends-name-%')->get();
            $this->data['arranges'] = Frag::where('slug','like','wedding-arrange-%')->get();
            return view('system.wedding')->with($this->data);
        }
        if(cache("kv_site_open") == 0) { //网站关闭
            return view('errors.404');
        }

    }

    public function story()
    {
        if(cache("kv_site_open") == 1){
            //个人信息
            $this->data['storys'] = Frag::where('slug','like','story-%')->get();
            $this->data['arranges'] = Frag::where('slug','like','wedding-arrange-%')->get();
            return view('system.story')->with($this->data);
        }
        if(cache("kv_site_open") == 0) { //网站关闭
            return view('errors.404');
        }
    }
    public function ceremony()
    {
        if(cache("kv_site_open") == 1){
            //个人信息
            $this->data['ceremonys'] = Frag::where('slug','like','ceremony-title-%')->get();
            $this->data['arranges'] = Frag::where('slug','like','wedding-arrange-%')->get();
            return view('system.ceremony')->with($this->data);
        }
        if(cache("kv_site_open") == 0) { //网站关闭
            return view('errors.404');
        }
    }
    public function albums()
    {
        if(cache("kv_site_open") == 1){
            //个人信息
            $this->data['albums'] = Frag::where('slug','like','picture-%')->get();
            $this->data['arranges'] = Frag::where('slug','like','wedding-arrange-%')->get();
            return view("system.albums")->with($this->data);
        }
        if(cache("kv_site_open") == 0) { //网站关闭
            return view('errors.404');
        }

    }
    public function contactPage()
    {
        if(cache("kv_site_open") == 1){

            $this->data['arranges'] = Frag::where('slug','like','wedding-arrange-%')->get();
            return view("system.contact_page")->with($this->data);
        }
        if(cache("kv_site_open") == 0) { //网站关闭
            return view('errors.404');
        }

    }
    /**
     * 游客咨询
     */

    public function contact (Request $request)
    {
        $feed = new MFeedback;
        if ($feed->saveFeed($request,$feed)) {
            $this->data = $this->makeJscode(0,'发送成功');
        } else {
            $this->data = $this->makeJscode(1,'发送失败');
        }

        return response()->json($this->data);
    }

}